<template>
  <div class="app-container">
    <!-- 查询模块 -->
    <div class="formDiv">
      <el-form ref="form" :inline="true" label-width="130px">
        <el-row>
          <el-col :span="6">
            <el-form-item label="流水单号">
              <el-input v-model="params.orderSn" placeholder="请输入流水单号" clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="姓名">
              <el-input v-model="params.userName" placeholder="请输入客户姓名" clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="手机号">
              <el-input v-model="params.userPhone" placeholder="请输入客户手机号" clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="退款单号">
              <el-input v-model="params.refundOrderId" placeholder="请输入退款单号" clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="退款时间">
              <el-date-picker
                type="daterange"
                value-format="yyyy-MM-dd HH:mm:ss"
                range-separator="-"
                start-placeholder="开始时间"
                end-placeholder="结束时间"
                v-model="time"
                :default-time="['00:00:00', '23:59:59']"
              ></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12" style="text-align: right;">
            <el-button type="primary" @click="searchFn">查询</el-button>
            <el-button
              type="primary"
              @click="excelEvent"
              v-if="permissionJson.indexOf('AdminRefundOrderProvider.exportRefundOrder') !=-1"
            >导出</el-button>
            <!-- <el-button type="primary" @click="excelEvent">导出</el-button> -->
          </el-col>
        </el-row>
      </el-form>
    </div>
    <!-- table -->
    <div class="table" v-loading="tableLoading">
      <el-table ref="multipleTable" :data="tableData" tooltip-effect="dark" style="width: 100%">
        <el-table-column type="index" width="55" label="序号"></el-table-column>
        <el-table-column prop="orderSn" align="center" label="流水单号"></el-table-column>
        <el-table-column prop="hospitalName" align="center" label="医院名称"></el-table-column>
        <el-table-column prop="reimbursementRatio" align="center" label="回款比率"></el-table-column>
        <el-table-column prop="userName" align="center" label="客户姓名"></el-table-column>
        <el-table-column prop="userPhone" align="center" label="客户电话">
          <template slot-scope="scope">
            <span>{{scope.row.userPhone |phonereg}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="allPrice" align="center" label="扣除杂费金额"></el-table-column>
        <el-table-column prop="sundryPrice" align="center" label="杂费金额"></el-table-column>
        <el-table-column prop="orderId" align="center" label="退款单号"></el-table-column>
        <el-table-column prop="amount" align="center" label="退款金额"></el-table-column>
        <el-table-column prop="refundAmount" align="center" label="子商户扣除金额"></el-table-column>
        <el-table-column prop="feeAmount" align="center" label="平台扣除金额"></el-table-column>
        <el-table-column prop="createdAt" align="center" label="退款时间"></el-table-column>
      </el-table>
    </div>
    <div class="pagesCon">
      <div>
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="params.pageNum"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="params.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        ></el-pagination>
      </div>
    </div>
  </div>
</template>
<script>
import { getList, excelExport } from "@/api/Refundinquiry";
import { exportfile } from "@/api/exporfile";

export default {
  name: "Refundinquiry",
  data() {
    return {
      // loading层
      tableLoading: false,
      permissionJson: JSON.parse(localStorage.getItem("permissionJson")),
      //提交查询数据
      params: {
        pageNum: 1,
        pageSize: 10,
        orderSn: "",
        userName: "",
        userPhone: "",
        refundOrderId: "",
        refundStartTime: "",
        refundEndTime: "",
        targetId: -1
      },
      tableData: [],
      total: 0,
      time: []
    };
  },
  inject: ["reload"],
  //过滤
  filters: {},
  mounted() {
    this.getList(this.params);
  },
  methods: {
    //列表
    getList(e) {
      this.tableLoading = true;
      const datas = e;
      getList(datas)
        .then(res => {
          // console.log(res);
          if (!res.data.code) {
            this.tableData = res.data.data.list;
            this.total = res.data.data.count;
          } else {
            this.$message.error(res.data.msg);
          }
          this.tableLoading = false;
        })
        .catch(error => {
          this.$message.error(error);
          this.tableLoading = false;
        });
    },
    // 查询
    searchFn() {
      this.params.pageNum = 1;
      // console.log(this.params)
      if (this.time != null) {
        if (this.time.length) {
          this.params.refundStartTime = this.time[0];
          this.params.refundEndTime = this.time[1];
        }
      } else {
        this.params.refundStartTime = null;
        this.params.refundEndTime = "";
      }
      this.getList(this.params);
    },
    //导出
    excelEvent() {
      let datas = { ...this.params };
      // delete datas.pageNum
      // delete datas.pageSize
      excelExport(this.params).then(res => {
        exportfile(res);
      });
    },

    // 改变页面条数
    handleSizeChange(val) {
      // this.params.pageNum = 1;
      this.params.pageSize = val;
      this.getList(this.params);
    },
    // 选择页数
    handleCurrentChange(val) {
      this.params.pageNum = val;
      this.getList(this.params);
    }
  }
};
</script>
<style scoped>
/* 分页 */
.pagesCon {
  height: 40px;
  margin-top: 20px;
}
.pagesCon > div {
  float: right;
}
/* 表单样式修改 */
.el-range-editor--medium.el-input__inner {
  width: 236px;
}
</style>